﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fn="http://www.w3.org/2005/xpath-functions"
                xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" 
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
                xmlns:o="urn:schemas-microsoft-com:office:office"
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
                xmlns:v="urn:schemas-microsoft-com:vml"
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
                xmlns:w10="urn:schemas-microsoft-com:office:word"
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
                xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
                xmlns:space="default"
                xmlns:a="http://www.tei-c.org/ns/1.0"
                exclude-result-prefixes="xs fn xdt ve o r m v wp w10 w wne a space pkg">
    <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <TEI>
      <xsl:call-template name="teiHeader"/>
      <xsl:call-template name="text"/>
    </TEI>
  </xsl:template>
  
  <xsl:template name="teiHeader">
    <teiHeader>
      <fileDesc>
        <titleStmt>
          <title></title>
          <author></author>
        </titleStmt>
        <publicationStmt>
          <p/>
        </publicationStmt>
        <sourceDesc>
          <p/>
        </sourceDesc>
      </fileDesc>
    </teiHeader>
  </xsl:template>
  
  <xsl:template name="text">
    <text>
      <xsl:call-template name="front"/>
      <xsl:call-template name="body"/>
      <xsl:call-template name="back"/>
    </text>
  </xsl:template>

  <xsl:template name="front">
    <front>
      
    </front>
  </xsl:template>

  <xsl:template name="body">
    <body>
      <xsl:apply-templates/>
    </body>
  </xsl:template>

  <xsl:template name="back">
    <back>
      
    </back>
  </xsl:template>
  
  <!--Paragraphs-->
  <xsl:template match="w:p">
    <!--handle styles-->
    <!--<xsl:for-each select="w:pPr">
      <xsl:for-each select="w:pStyle">-->
        <xsl:choose>
          <xsl:when test="w:pPr/w:pStyle[@w:val='Quote']">
            <q>
              <p><xsl:apply-templates/></p>
            </q>
          </xsl:when>
          <xsl:when test="w:pPr/w:pStyle[@w:val='Title']">
            <title>
              <xsl:apply-templates/>
            </title>
          </xsl:when>
          <xsl:when test="w:pPr/w:pStyle[@w:val='Heading1']">
            <head>
              <xsl:apply-templates/>
            </head>
          </xsl:when>
          <xsl:otherwise>
            <p>
              <xsl:apply-templates/>
            </p>
          </xsl:otherwise>
        </xsl:choose>
        
      <!--</xsl:for-each>-->
      
    <!--<w:pPr>
      <w:pStyle w:val="Quote"/>
    </w:pPr>-->
      
      
    <!--</xsl:for-each>-->
    
    <!--<xsl:for-each select="w:r">
      <xsl:apply-templates/>
    </xsl:for-each>-->
    
  </xsl:template>

  <xsl:template match="w:r">
    <!--Handle Styles-->
    <xsl:choose>
      <xsl:when test="w:rPr/w:rStyle[@w:val='Emphasis']">
        <emph rend="Emphasis">
          <xsl:apply-templates/>
        </emph>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="w:t">
    <xsl:apply-templates/>
  </xsl:template>

  <!--Endnotes-->
  <xsl:template match="w:endnoteReference">
    <xsl:variable name="endnoteID" select="@w:id"/>
    <!--Endnote ID: <xsl:value-of select="$endnoteID"/>-->
    <note place="end" type="endnote">
      <xsl:apply-templates select="//w:endnote[@w:id=$endnoteID]"/>
    </note>
  </xsl:template>
  
  <!--Elements to Ignore-->
  <xsl:template match="//pkg:part[@pkg:name='/word/footnotes.xml'] | pkg:part[@pkg:name='/word/endnotes.xml']"/>
  
  <!--<xsl:template name="Endnote">
    <xsl:param name="ID">0</xsl:param>
    <xsl:for-each select="w:r">
      <xsl:apply-templates/>
    </xsl:for-each>
  </xsl:template>-->
  
  <!--style templates-->
  <!--<xsl:template match="w:pStyle[@w:val='Quote']">
    <q>
      
    </q>
  </xsl:template>-->
  
  
  <!--text-->
  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>
    <!--<xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>-->
</xsl:stylesheet>
